package org.jaaksi.demo.ptr.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import org.jaaksi.demo.ptr.R;
import org.jaaksi.demo.ptr.bean.house.HouseListBean;

/**
 * Created by Fcy on 2016/3/18.<br/>
 */
public class HouseAdapter extends BaseSimpleAdapter<HouseListBean, HouseAdapter.ItemHolder> {

  public HouseAdapter(Context context) {
    super(context);
  }

  @Override public int getLayoutId() {
    return R.layout.item_house;
  }

  @Override public ItemHolder onCreateViewHolder(View convertView) {
    return new ItemHolder(convertView);
  }

  @Override
  public void onBindViewHolder(ItemHolder holder, HouseListBean houseListBean, int position) {
    HouseListBean item = getItem(position);
    holder.resName.setText(item.title);
    holder.resArea.setText(item.min_frame_area + "㎡");
    holder.resPrice.setText(item.avg_unit_price + "元/㎡");
    //		picasso.load(new File(thumbUrl))
    //		        .placeholder(R.drawable.icon_gridview_picture_normal)
    //		        .error(R.drawable.icon_gridview_picture_normal)
    //		        .networkPolicy(NetworkPolicy.NO_CACHE).noFade().fit()
    //		        .centerCrop().tag(thumbUrl).into(holder.iv_house_img);
    // Adapter的重用会被自动检测到，Picasso会取消上次的加载

    mPicasso.load(item.cover_pic + ".360x270.jpg")
        .placeholder(R.drawable.img_defult)
        .error(R.drawable.img_defult)
        .into(holder.iv_house_img);
  }

  static class ItemHolder {
    private TextView resName, resArea, resPrice;
    private ImageView iv_house_img;

    public ItemHolder(View view) {
      resName = (TextView) view.findViewById(R.id.tv_res_name);
      resArea = (TextView) view.findViewById(R.id.tv_res_area);
      resPrice = (TextView) view.findViewById(R.id.tv_res_price);
      iv_house_img = (ImageView) view.findViewById(R.id.iv_house_img);
    }
  }
}
